package net.learn;

import net.learn.piggy.bean.User;
import net.learn.piggy.domain.MySource;
import net.learn.piggy.initializer.MyApplicationContextInitializer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import java.util.HashSet;

@SpringBootApplication
public class LearnApplication {
    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(LearnApplication.class);
//        springApplication.addBootstrapRegistryInitializer(new MyBootstrapRegistryInitializer());
        springApplication.addInitializers(new MyApplicationContextInitializer());


        springApplication.setSources(new HashSet<String>(){{this.add(MySource.class.getName());}});

        ConfigurableApplicationContext context = springApplication.run(args);

        System.out.println("=====================================================================================");

        User user = context.getBean(User.class);
        System.out.println(user);

        MySource source = context.getBean(MySource.class);
        System.out.println(source);

        ServletConfig servletConfig = context.getBean(ServletConfig.class);
        System.out.println(servletConfig);

        ServletContext servletContext = context.getBean(ServletContext.class);
        System.out.println(servletContext);
    }
}
